import os
import json
import pandas as pd
import matplotlib.pyplot as plt

with open(f'fts/aa100_20200205.log', 'r+') as f:
    a = f.readlines()

M = {}
for i in range(len(a)//3):
    err = a[i*3+1].strip()
    err_str = err.replace('std:,', 'std2:')
    err_arr = err_str.split(',')
    if i == 0:
        M['name'] = [a[3*i+2].strip()]
    else:
        M['name'] += [a[3*i+2].strip()]
    for ta in err_arr:
        key, val = ta.split(':')[0].strip(), ta.split(':')[1].strip()
        if key not in M:
            M[key] = [float(val)]
        else:
            M[key] += [float(val)]


A = pd.DataFrame(M)
A = A.sort_values(['oof val f1'], ascending=True)
x1, y1, dy1 = range(A.shape[0]), A['oof val f1'], A['std']
plt.errorbar(x1, y1, yerr=dy1, fmt='o', ecolor='r', color='b', elinewidth=1, capsize=4)
x2, y2, dy2 = range(A.shape[0]), A['oof res f1'], A['std2']
plt.errorbar(x2, y2, yerr=dy2, fmt='o', ecolor='r', color='b', elinewidth=1, capsize=4)
plt.show()

A['F1'] = (A['oof val f1']+A['oof res f1'])/2
A['STD'] = (A['std']+A['std2'])/2
A = A.sort_values(['F1'], ascending=False)


x = x1
y = (y1+y2)/2
dy = (dy1+dy2)/2
plt.errorbar(x, y, yerr=dy, fmt='o', ecolor='r', color='b', elinewidth=1, capsize=4)
plt.show()
